<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cookie;
use think\Config;
class Basic extends Controller{
	public function _initialize(){
        isinstall();
		$user = [];
		Config::load(APP_PATH.'field.php');
		$this->safe = new \kykkk\Safe(config('safekey'));
		$this->navt = $navt = new \kykkk\Nav();
		$this->orgnav = get_orgnav('home',LID);
		$this->assign('navt',$navt);
		$this->assign('orgnav',$this->orgnav);

		$cfg = get_config($this->safe,LID,true);

		$this->cfg = $cfg;
		foreach($cfg as $k=>$v){
			$this->assign($k,$v);
		}

		$this->assign('style',STYLE_PATH);
		$this->assign('navlist',$navt::getNavList($this->orgnav));
		
		$user= [];
		if($this->cfg['open_member'] == 'y'){
			$this->user = $user = checklogin();
			
		}

		if($user){
			$this->assign('cartnum',Db::name('shopcart')->where('mid',$this->user['id'])->count());
			$this->assign('carturl','/member_trading_cartlist.html');
			$this->assign('islogin','yes');
			$this->assign('user',$this->user);
			if(Cookie::has('gid') && Cookie::has('sid') && Cookie::has('buynum')){
				$gid = intval(Cookie::get('gid'));
				$sid = intval(Cookie::get('sid'));
				$num = intval(Cookie::get('buynum'));
				$token = sha1($user['id'].$sid.$num);
				$url = url('/member/order/orderbynow',['sid'=>$sid,'gid'=>$gid,'num'=>$num,'token'=>$token]);
				$this->redirect($url);
			}
			$this->assign('islogin','y');
		}else{
			$this->assign('cartnum',0);
			$this->assign('carturl','/cartlist');
			$this->assign('islogin','n');
		}

		$this->assign('isindex','n');
		$this->assign('user',$user);
		$this->assign('title',$cfg['webname']);
		$this->prefix = config('database.prefix');
		$this->assign('prefix',$this->prefix);
		$this->assign('m_name',mname());

		$this->assign('calarr',getall($this->prefix.'cal',['status'=>1],'id asc',true));
		
	}
	
}